import pygame
from pygame.locals import *
from Widget import *

class Entry(Widget):
   def __init__(self, x_, y_, chars, buffer_, font_, fontSize_):
      Widget.__init__(self)
      self.font = pygame.font.Font(font_, fontSize_)
      self.rect = pygame.Rect(x_, y_, fontSize_*chars, self.font.get_height())
      self.buffer = buffer_
      self.labelSurface = self.font.render(self.buffer, 1, (255,255,255))
      
   def draw(self):
      pygame.draw.rect(self.screen, (95,95,95), 
         (  self.parent.rect.x+self.rect.x, 
            self.parent.rect.y+self.rect.y,
            self.rect.w, 
            self.rect.h+4))
      pygame.draw.rect(self.screen, (0,0,0), 
         (  self.parent.rect.x+self.rect.x+1, 
            self.parent.rect.y+self.rect.y+1, 
            self.rect.w-2, 
            self.rect.h-2+4))
      labelX = self.getX() + 4
      labelY = (self.getY()) + self.rect.h/2 - (self.labelSurface.get_height()/2) + 2
      self.screen.blit(self.labelSurface, ( labelX, labelY, self.rect.w,self.rect.h))
      
   def add_char(self, char):
      self.buffer += unichr(char)
      
   def get_buffer(self):
      return self.buffer